Skip to content

feat(fspy_elf_loader): add SIGSYS syscall interception, signal virtualization, and /proc/exe rewriting - #1028

Open
wan9chi wants to merge 10 commits into
fspy-linux/2-elf-loader-validation-stackfrom
fspy-linux/3-elf-loader-sigsys
Open

wan9chi wants to merge 10 commits into
fspy-linux/2-elf-loader-validation-stackfrom
fspy-linux/3-elf-loader-sigsys

Conversation

@wan9chi

@wan9chi wan9chi commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Motivation

To track filesystem accesses uniformly across glibc, musl, static binaries, and direct-syscall runtimes on Linux without LD_PRELOAD or seccomp_unotify, the userland ELF loader needs an in-process seccomp-BPF SECCOMP_RET_TRAP (SIGSYS) virtualization runtime that transparently preserves target signal semantics, vfork/posix_spawn, multithreading, and /proc/*/exe identity while exposing a clean syscall-interception hook.

Changes

  • sigsys/filter.rs: seccomp-BPF filter allowlisting the launcher's fixed PF_X range, rejecting io_uring_setup and clone3 with ENOSYS, and trapping signal, exec, /proc/*/exe, and caller-supplied syscalls (with unit tests).
  • sigsys/signal.rs, sigsys/arch.rs, and sigsys/stack_pool.rs: per-thread virtual SIGSYS disposition/mask virtualization, pooled private SIGSYS stacks, vfork/posix_spawn altstack handoff returning via rt_sigreturn (relocating x86-64 fpregs; CET shadow stacks, Arm GCS, and SME EXTRA_MAGIC frames are unsupported), and masked-wait deferred-SIGSYS handling (with unit tests).
  • sigsys/proc_exe.rs and sigsys/usermem.rs: /proc/*/exe path rewriting (with unit tests) and user memory copies that, like the macOS and Windows preloads, assume the pointers passed to syscalls are valid.
  • fspy_elf_loader_test_launcher and fspy_elf_loader_tests: wire --test-interceptor and add the 38-test Linux virtualization integration suite in fixtures/virtualization.c and tests/exec_elf.rs.

Stack created with GitHub Stacks CLI • Give Feedback 💬


Note

High Risk
Adds seccomp filtering, signal virtualization, and exec/fork/vfork handling on the critical Linux spawn path; regressions could break process startup, threading, or syscall identity for tracked workloads.

Overview
Introduces a seccomp-BPF SIGSYS runtime inside fspy_elf_loader so Linux targets can be launched through the freestanding loader while still seeing correct process identity and controllable syscall hooks.

exec_elf now validates the launcher’s fixed high-address PF_X range, installs the virtualization stack (optional SyscallInterceptor), then maps and enters the target as before. Public types Syscall, SyscallAction, and helpers like user_cstr support interceptors that can replay traps, short-circuit with errno, or replace execution via Execve.

The new sigsys subsystem builds and installs a BPF filter (filter.rs) that allowlists launcher code, idempotently detects re-exec, returns ENOSYS for clone3 / io_uring_setup, and conditionally traps signal, fork/vfork, masked waits, /proc/*/exe path syscalls, plus caller-listed syscalls. arch.rs supplies x86-64 and AArch64 naked trampolines, syscall replay, and vfork altstack handoff; proc_exe.rs rewrites or answers /proc/*/exe lookups; stack_pool.rs and signal handlers virtualize masks/dispositions under load.

Docs and deps add errno/ptrace linux-raw-sys features and alloc helpers; fspy_elf_loader_tests gain **virtualization.c fixtures and a large integration suite (signal masking, proc exe, posix_spawn, nested seccomp, FIFO EINTR, etc.), with --test-interceptor on the test launcher.

Reviewed by Cursor Bugbot for commit d21f57b. Bugbot is set up for automated code reviews on this repo. Configure here.

@wan9chi
wan9chi added this pull request to stack #1030 November 27, 2026 00:33
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +0.41%  [ -4.94% ..  +4.38%]  overhead   +57.03%
dynamic/access             change  -0.44%  [ -7.07% ..  +2.81%]  overhead   +17.09%
dynamic/access-relative    change  +0.31%  [ -3.14% ..  +4.75%]  overhead   +69.81%
dynamic/access-contended   change  -0.64%  [ -6.48% ..  +9.66%]  overhead    +6.02%
static/launch              change  +1.42%  [ -2.87% ..  +7.51%]  overhead  +197.50%
static/access              change  -0.19%  [ -3.66% ..  +2.37%]  overhead +1458.99%
static/access-relative     change  -0.48%  [ -3.20% ..  +2.87%]  overhead +1972.51%
static/access-contended    change  -0.17%  [ -3.86% ..  +9.37%]  overhead +1714.05%

macos

dynamic/launch             change  -0.19%  [ -2.91% ..  +2.53%]  overhead  +228.16%
dynamic/access             change  +0.39%  [ -1.91% ..  +2.45%]  overhead    +5.20%
dynamic/access-relative    change  +0.41%  [ -3.41% ..  +3.80%]  overhead  +249.26%
dynamic/access-contended   change  -0.47%  [ -2.77% ..  +2.84%]  overhead    +3.05%

windows

dynamic/launch             change  +0.00%  [ -3.62% ..  +4.35%]  overhead   +27.05%
dynamic/access             change  -0.35%  [ -5.43% ..  +2.71%]  overhead    +1.65%
dynamic/access-relative    change  +0.18%  [ -1.43% ..  +1.59%]  overhead    +1.48%
dynamic/access-contended   change  -0.68%  [ -6.69% ..  +9.44%]  overhead    +1.06%

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

wan9chi and others added 3 commits November 27, 2026 08:45
…lization, and /proc/exe rewriting

Add the in-process SIGSYS syscall virtualization engine to
`fspy_elf_loader`, wire it into the freestanding test launcher, and add
unit and Linux virtualization integration tests:

- `sigsys/filter.rs`: seccomp-BPF filter construction allowlisting the
  launcher's `PF_X` range, rejecting `io_uring_setup` with `ENOSYS`,
  and trapping signal/exec/`/proc/exe` and caller-supplied syscalls.
- `sigsys/signal.rs` & `sigsys/arch.rs`: per-thread virtual `SIGSYS`
  disposition/mask virtualization, pooled SIGSYS stacks, `vfork` /
  `posix_spawn` altstack handoff with `rt_sigreturn` (including AArch64
  `EXTRA_MAGIC`/GCS and x86-64 `fpregs`/CET handling), and masked-wait
  deferred-SIGSYS handling.
- `sigsys/proc_exe.rs` & `sigsys/usermem.rs`: `/proc/*/exe` path
  rewriting and fault-safe user memory copy/probe helpers.
- `fspy_elf_loader_tests`: 39-test Linux integration suite in
  `fixtures/virtualization.c` and `tests/exec_elf.rs`.

Co-authored-by: Gemini 4 Neon <noreply@google.com>
Co-authored-by: Gemini 4 Neon <noreply@google.com>
…lter

Co-authored-by: Gemini 4 Neon <noreply@google.com>
@wan9chi
wan9chi force-pushed the fspy-linux/3-elf-loader-sigsys branch from c34be75 to 17f3396 Compare November 27, 2026 00:46

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

wan9chi and others added 4 commits November 27, 2026 10:45
… of via process_vm_readv

The SIGSYS runtime copied every user pointer it read or wrote (paths,
`struct sigaction`, signal sets, `open_how`, timeouts, the
`/proc/self/exe` readlink buffer) through `process_vm_readv` /
`process_vm_writev` on its own pid, so a bad pointer returned `EFAULT`
instead of crashing the handler. That costs a `getpid` plus a copy
syscall per pointer, and it breaks under filters the target installs
itself: Chromium's sandboxed renderer traps `process_vm_readv`, and the
trap reached Chromium's handler, which crashed the renderer.

Assume the pointers are valid, as the macOS and Windows preloads already
do for the calls they interpose, and access them directly. Addresses in
the first page (`NULL`, small integers) still fail with `EFAULT` without
being touched. The copy helpers become `unsafe fn` with that contract.
Abseil's `rt_sigprocmask(~0, addr)` address probe already goes straight
to the kernel, so it keeps returning `EFAULT`/`EINVAL` as before.

Tests that checked fault-safe copies of bad pointers, including the
`process_vm_*`-denied fallback, are removed; the Abseil probe cases stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ched_cstr

Now that `usermem` reads trapped syscall arguments directly instead of
copying through `process_vm_readv`, copying path arguments into a 4 KiB
stack buffer in `dispatch_phase1` / `proc_exe::rewrite_path_arg` and
caching that slice on `Syscall` is unnecessary:

- Replace `usermem::read_user_cstr` / `copy_user_cstr` with zero-copy
  `user_cstr(addr) -> Result<CStr<'_, Thin>>` (still rejecting page 0
  with `Error::FAULT`).
- Remove `Prefetched::path`, `Syscall::cached_cstr`, and the 4 KiB
  `path_buf` from `dispatch_phase1` and `proc_exe::rewrite_path_arg`.
- Update `fspy_elf_loader_test_launcher` to use `user_cstr` directly.

Co-authored-by: Gemini 4 Neon <noreply@google.com>
…ux/3-elf-loader-sigsys

# Conflicts:
#	crates/fspy_elf_loader/src/lib.rs
…om the vfork path

The vfork/posix_spawn child returns through a copied signal frame. The
copy also disabled an x86 CET shadow stack or an Arm GCS in the child
(with a hand-written register restore when either was locked), cleared
the GCS record, and relocated SVE/SME `EXTRA_MAGIC` payloads.

None of that runs for real programs: userspace CET shadow stacks are
opt-in, GCS needs hardware that isn't deployed, and the kernel discards
SVE state on syscall entry, so a trapped frame only outgrows `__reserved`
with live SME `ZA` state. Copy the fixed-size frame and return via
`rt_sigreturn` instead; such processes are documented as unsupported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

There are 5 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8871c06. Configure here.

wan9chi and others added 2 commits November 27, 2026 12:24
The typos check rejects the bare abbreviation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…roc/*/exe comment

`lstat` never follows `/proc/self/exe`, so trapping it in the base set
only added a SIGSYS round trip. The `/proc/*/exe` matcher does not
resolve paths relative to the cwd; say so instead of claiming it does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Agentic security review found one high-severity issue: the native-architecture gate allowlists all foreign/compat syscalls, which bypasses the SIGSYS interception this PR otherwise enforces.

Open in Web View Automation 

Sent by Cursor Security Agent: Security Reviewer

…_exe

`AT_FDCWD` is `-100` on Linux, not `-1`, so `BorrowedFd::try_borrow_raw`
returns `Some(CWD)` and `fd_path` resolves `getcwd`. Restore the comment
to match the actual behavior.

Co-authored-by: Gemini 4 Neon <noreply@google.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant